const { CarComments } = require('../models/carCommentsModel')


//新增车辆评价
async function addCarComments(req, res) {
    const { userID, orderID, carID, content, score, createDate } = req.body;
    const data = await CarComments.create({ userID, orderID, carID, content, score, createDate })
    try {
        if (data) {
            res.send({
                status: 1,
                msg: '新增成功',
                data
            })
        }
    } catch (error) {
        console.log('error', error);
    }
}
//获取评价
async function getCarComments(req,res){
   const data =  await CarComments
   .find()
   .populate('userID')
   .populate('carID')
   .populate('orderID')
    try {
        res.send({
            status:1,
            msg:'获取成功',
            data
        })
    } catch (error) {
        console.log('error', error);
    }
}
//删除
async function deletCarComments(req,res){
    const _id = req._id;
    const data = await CarComments.deleteOne(_id)
    try {
       if(data){
        res.send({
            status:1,
            msg:'删除成功',
        })
       }
    } catch (error) {
        console.log('error', error);
    }
}
module.exports = { addCarComments ,getCarComments,deletCarComments};